<template>
  <view class="service-card" @click="handleClick">
    <image :src="service.image" mode="aspectFill" class="card-image"></image>
    <view class="card-info">
      <text class="card-title ellipsis">{{ service.name }}</text>
      <view class="card-price">
        <text class="price-now">¥{{ service.price }}{{ service.unit }}</text>
        <text class="price-old">¥{{ service.originalPrice }}</text>
      </view>
      <view class="card-footer">
        <view class="card-score">
          <rating-star :rating="service.score" size="20rpx"></rating-star>
          <text class="score-text">{{ service.score }}</text>
        </view>
        <text class="card-sales">已售{{ service.sales }}</text>
      </view>
    </view>
  </view>
</template>

<script>
import RatingStar from '../rating-star/rating-star.vue'

export default {
  components: {
    RatingStar
  },
  props: {
    service: {
      type: Object,
      required: true
    }
  },
  methods: {
    handleClick() {
      this.$emit('click');
    }
  }
}
</script>

<style lang="scss">
.service-card {
  width: 640rpx;
  background-color: #fff;
  border-radius: 12rpx;
  overflow: hidden;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
  
  .card-image {
    width: 100%;
    height: 440rpx;
  }
  
  .card-info {
    padding: 16rpx;
    
    .card-title {
      font-size: 28rpx;
      font-weight: bold;
      color: #333;
      margin-bottom: 10rpx;
    }
    
    .card-price {
      display: flex;
      align-items: baseline;
      margin-bottom: 10rpx;
      
      .price-now {
        font-size: 30rpx;
        font-weight: bold;
        color: #FF7D00;
      }
      
      .price-old {
        font-size: 24rpx;
        color: #999;
        text-decoration: line-through;
        margin-left: 10rpx;
      }
    }
    
    .card-footer {
      display: flex;
      justify-content: space-between;
      align-items: center;
      
      .card-score {
        display: flex;
        align-items: center;
        
        .score-text {
          font-size: 22rpx;
          color: #999;
          margin-left: 6rpx;
        }
      }
      
      .card-sales {
        font-size: 22rpx;
        color: #999;
      }
    }
  }
}

.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>